/*
 * 文件名:    TriangleIndicator
 * 创建时间:  3/2/21 on 11:30 AM
 * 描述:     TODO
 *
 * @author   阿钟
 */
import 'dart:ui';

import 'package:flutter/material.dart';

class TriangleIndicator extends Decoration {
  ///三角形的大小
  final Size triangleSize;

  ///选中的颜色
  final Color color;

  TriangleIndicator(this.triangleSize, this.color);

  @override
  BoxPainter createBoxPainter([VoidCallback onChanged]) {
    return _CustomBoxPainter(triangleSize, color);
  }
}

class _CustomBoxPainter extends BoxPainter {
  final Size triangleSize;
  final Color color;

  _CustomBoxPainter(this.triangleSize, this.color);
  /// The PI constant.
  static const double pi = 3.1415926535897932;
  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    ///每个Tab的宽高
    Size tabSize = Size(configuration.size.width,
        configuration.size.height - triangleSize.height);
    final Rect rect = offset & tabSize;
    final Paint paint = Paint();
    double pi0 = 3.14;
    paint.color = color;
    paint.style = PaintingStyle.fill;


    // ///画Tab矩形
    // canvas.drawRect(rect, paint);
    //
    // ///画三角形
    // double start = (tabSize.width - triangleSize.width) / 2;
    // Path trianglePath = Path();
    //
    // ///起点
    // trianglePath.moveTo(
    //     start + offset.dx, configuration.size.height - triangleSize.height);
    //
    // ///中点
    // trianglePath.lineTo(
    //     (tabSize.width / 2) + offset.dx, configuration.size.height);
    //
    // ///终点
    // trianglePath.lineTo(start + offset.dx + triangleSize.width,
    //     configuration.size.height - triangleSize.height);
    // canvas.drawPath(trianglePath, paint);
  }
}
